<template>
  <div class="about">
 我是about
 <button @click="find()">我要找到子集</button>
  </div>
</template>
<script>
import   editPageLeavePrompt from '../mix/edit-page-leave-prompt'
export default {
mixins: [editPageLeavePrompt],
  name: 'AboutView',
  data() {
    return {
      msg: 'hello world',
      datas: [
        {
          "id": "001",
          "name": "电子产品",
          "category": "goods",
          "children": [
            {
              "id": "00101",
              "name": "手机",
              "brand": "华为",
              "children": [
                {
                  "id": "0010101",
                  "name": "P60 Pro",
                  "price": 6999
                },
                {
                  "id": "0010102",
                  "name": "Mate 50",
                  "price": 4999
                }
              ]
            },
            {
              "id": "00102",
              "name": "笔记本电脑",
              "brand": "联想",
              "children": [
                {
                  "id": "0010201",
                  "name": "拯救者Y9000P",
                  "price": 9999
                }
              ]
            }
          ]
        },
        {
          "id": "002",
          "name": "图书音像",
          "category": "goods",
          "children": [
            {
              "id": "00201",
              "name": "编程书籍",
              "type": "technology",
              "children": [
                {
                  "id": "0020101",
                  "name": "Vue实战指南",
                  "author": "张三"
                }
              ]
            }
          ]
        },
        {
          "id": "003",
          "name": "家居用品",
          "category": "goods",
          "children": [
            {
              "id": "00301",
              "name": "床上用品",
              "type": "textiles",
              "children": [
                {
                  "id": "0030101",
                  "name": "纯棉四件套",
                  "price": 399
                }
              ]
            },
            {
              "id": "00302",
              "name": "厨房用具",
              "type": "cookware",
              "children": [
                {
                  "id": "0030201",
                  "name": "不锈钢炒锅",
                  "price": 199
                }
              ]
            }
          ]
        },
        {
          "id": "004",
          "name": "美妆个护",
          "category": "goods",
          "children": [
            {
              "id": "00401",
              "name": "护肤品",
              "brand": "兰蔻",
              "children": [
                {
                  "id": "0040101",
                  "name": "小黑瓶精华",
                  "price": 1080
                }
              ]
            }
          ]
        },
        {
          "id": "005",
          "name": "食品饮料",
          "category": "goods",
          "children": [
            {
              "id": "00501",
              "name": "零食",
              "type": "snacks",
              "children": [
                {
                  "id": "0050101",
                  "name": "巧克力",
                  "brand": "德芙"
                }
              ]
            }
          ]
        }
      ]
    }
  },
  methods: {
    demo() {
     console.log('我要执行接口');
     
    },
    findid(arr, id) {
      if (arr && arr.length > 0) {
        for (const item of arr) {
          if (item.id === id) {
            return item;
          } else if (item.children && item.children.length > 0) {
            const result = this.findid(item.children, id);
            if (result) {
              return result;
            }
          }
        }
      }
      return null;
    },
    find() {
      this.findid(this.datas, '0010101')
      console.log(this.findid(this.datas, '0010101'));
      
    }
  },
}
</script>